#!/bin/bash

set -e

function mark2html {
    markdown "../data/"$1".md" > "html/"$1".html"
}

if [ ! -e "build" ]
then
  echo "The directory 'build' does not exist. Making directory now."
  mkdir build
else
  echo "The directory 'build' exists. The program will be built there."
fi

echo "Compiling the program now."

javac CipherBuddy.java -d build

echo "Copying MANIFEST.MF"

cp MANIFEST.MF build/

cd build

echo "Building CipherBuddy.jar"

jar cmf MANIFEST.MF CipherBuddy.jar *.class
chmod +x CipherBuddy.jar

echo "Done building! Removing unwanted files."

rm *.class

rm MANIFEST.MF
if [ ! -e "html" ]
then
  echo "The directory 'build/html' does not exist. Making directory now."
  mkdir html
else
  echo "The directory 'build/html' exists. Data will be put there."
fi

echo "Parsing Markdown files now."

for f in ../data/*.md
do
  echo "Parsing $f"
  mark2html `basename $f .md`
done

echo "Converting icon.svg to icon.png now."

inkscape -z -e html/icon.png -w 128 -h 128 ../data/icon.svg

echo "Building completed."
